var bodyParser = require('body-parser')
var urlencodedParser = bodyParser.urlencoded({
    extended: false
})
var express = require('express')
var db = require('../db.js')
var md5 = require('md5-nodejs')
var multer = require('multer');
var router = express.Router()


// 随机获取5个人
router.get('/get-broken-people', async function (req, res) {
    var sql = `select u.id,u.name from users as u order by rand() limit 5 `
    const { data } = await db.doSQL(sql)
    res.send(db.handleResults(data))
})

// 获取折线图需要的数据
router.get('/get-broken-data', async function (req, res) {
    let { id } = req.query
    // var sql = `select s.id,u.name,s.date,s.score from users as u,score as s where u.id=s.uid order by rand() limit 5`
    // var sql = `select s.uid,s.date,s.score from score as s where s.uid=${id}`
    var sql = `select s.date,s.score from score as s where s.uid=${id} order by rand() limit 5`
    const { data } = await db.doSQL(sql)
    res.send(db.handleResults(data))
})

module.exports = router;

